/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.kramerius.articles.importFromLn.cli;

import cz.mzk.kramerius.articles.importFromLn.articleImport.Rollbacker;
import cz.mzk.kramerius.commons.PropertyLoader;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Reverses import of articles. Uses importLog files stored in directory defined in properties.
 *
 * @author Martin Řehánek (rehan@mzk.cz)
 */
class RollbackImportAction implements Action {

    private static final Logger logger = Logger.getLogger(RollbackImportAction.class.getName());
    private final Rollbacker rollbacker;

    public RollbackImportAction(PropertyLoader properties) throws Exception {
        rollbacker = Rollbacker.instanceOf(properties);
    }

    @Override
    public void run() {
        try {
            int rollbacked = rollbacker.rollbackAllArticleImports();
            logger.log(Level.INFO, "Articles rollbacked: {0}", rollbacked);
        } catch (Exception ex) {
            logger.log(Level.SEVERE, null, ex);
        }
    }
}
